package models

import (
	"beegoProject/global"
	"fmt"
	"github.com/astaxie/beego/orm"
	"time"
)

type Video struct {
	Id          int
	Title       string    //标题
	Description string    //简介
	VideoUrl    string    //视频链接
	ImageUrl    string    //封面
	duration    int       //时长
	CreatedTime time.Time //
	UpdatedTime time.Time //
	Status      int       //上下架状态
	VideoType   int       //视频分类
}

func GetVideoListByPage(page int, size int) []Video {
	o := orm.NewOrm()
	var videos []Video
	_, err := o.QueryTable("video").Limit(size, (page-1)*size).All(&videos)
	if err != nil {
		panic(err)
	}
	return videos
}

func GetVideoCount() int64 {
	o := orm.NewOrm()
	count, err := o.QueryTable("video").Count()
	if err != nil {
		panic(err)
	}
	return count
}

func GetVideoListByPageAndGorm(page int, size int) []Video {
	var videos []Video
	var count int64
	// 计算偏移量
	offset := (page - 1) * size
	data := global.Db.Model(&videos).Limit(size).Offset(offset).Find(&videos)
	if data.Error != nil {
		panic(data.Error)
	}
	////查询数量
	total := global.Db.Model(&videos).Count(&count)
	fmt.Println(total)
	return videos
}
